#include "or.h"
#include "context.h"
#include "course.h"

Or::Or(shared_ptr<Requirement> lreq, shared_ptr<Requirement> rreq) :
    lreq_(lreq), rreq_(rreq)
{
}

/// Checks if the logical alternation of the requirements is fulfilled.
/// \param context Merely fulfills the interface signature of the function.
/// Not used.
/// \return True if the logical alternation of the requirements is fulfilled.
/// False otherwise.
bool Or::evaluate(Context& context)
{
    return lreq_->evaluate(context) || rreq_->evaluate(context);
}

/// Generates a string representation of the alternation expression.
/// \param context Merely fulfills the interface signature of the function.
/// Not used.
/// \return The string representation of the alternation expression.
std::string Or::to_string(Context& context)
{
    return lreq_->to_string(context) + " OR " + rreq_->to_string(context);
}

/// Counts the requirements in this alternation expression.
/// \param context Merely fulfills the interface signature of the function.
/// Not used.
/// \return The number of requirements in this alternation expression.
std::size_t Or::count(Context& context)
{
    return lreq_->count(context) + rreq_->count(context);
}

/// Gets the Course objects in this alternation expression.
/// \return A list of all Course objects in this alternation expression.
std::list<Course> Or::courses()
{
    std::list<Course> lreq_courses = lreq_->courses();
    std::list<Course> rreq_courses = rreq_->courses();
    lreq_courses.splice(lreq_courses.end(), rreq_courses);
    return lreq_courses;
}
